﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.core.database
{
    internal class ItemValue
    {
        public ItemValue(string name, object data)
        {
            Name = name;
            Data = data;
        }
        public string Name { get; set; }
        public object Data { get; set; }
        
    }
    public class DataItem
    {
        System.Collections.ArrayList _items;
        public DataItem()
		{
            _items = new System.Collections.ArrayList();
		}
        public object this[int index]
		{
			get
			{

                return ((ItemValue)_items[index]).Data;
			}
			set
			{
                ((ItemValue)_items[index]).Data = value;
			}
		}
        public object this[string name]
        {
            get
            {
                int index = FindItem(name);
                if (index > -1) return this[index];
                else return null;
            }
            set
            {
                int index = FindItem(name);
                if (index > -1) this[index] = value;
                else _items.Add(new ItemValue(name, value));
            }
        }
        int FindItem(string name)
        {
            for (int index = 0; index < _items.Count; index++)
            {
                ItemValue item = (ItemValue)_items[index];
                if (item.Name == name)
                    return (index);
            }
            return (-1);
        }
        public string[] Keys
        {
            get
            {
                string[] names = new string[_items.Count];
                for (int i = 0; i < _items.Count; i++)
                {
                    names[i] = ((ItemValue)_items[i]).Name;
                }
                return names;
            }
        }
    }
}
